package com.neusoft.error_handler;


import com.neusoft.exception.AuthFailException;
import com.neusoft.response.ApiResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(AuthFailException.class)
    public ApiResponse<String> handldUserExistException(AuthFailException exception) {
        return ApiResponse.error(401, exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ApiResponse<String> handldError(Exception exception) {
        return ApiResponse.error(500, exception.getMessage());
    }
}